﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; 
using PluginInterfacesLib;
using System.Windows.Controls;
using System.Media;
using System.IO;

namespace MusicPlugin
{
    class Brain : IPlugin
    {
        private Button wavButton;
        private string name;
        private IPluginHost host;
        private SoundPlayer player;

        public Button WavButton
        {
            get { return this.wavButton; }
            set { this.wavButton = value; }
        }

        public string Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        public IPluginHost Host
        {
            get
            {
                return this.host;
            }
            set
            {
                this.host = value;
            }
        }

        public Brain()
        {
            wavButton = new Button();
            player = new SoundPlayer();
        }

        public void Initialize()
        {
            
        }

        public void Initialize(IPluginHost Host)
        {
            this.name = "Music";
            this.Host = Host;
            
            wavButton.Content = "Play!";
            wavButton.Click += new System.Windows.RoutedEventHandler(wavButton_Click);

            DirectoryInfo dir=Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location);
            while (dir.Name != "MusicPlugin")
            {
                dir = dir.Parent;
            }

            player.SoundLocation = dir.FullName + @"\Sounds\daffyduck1.wav";
            player.LoadAsync();
            
            this.Host.AddButton();
        }

        void wavButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            player.Play();
        }

        public void Dispose()
        {
            throw new NotImplementedException();
        }
    }
}
